home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 1995 #5 & #6
/
Amiga Plus CD - 1995 - No. 5 and 6.iso
/
tex
/
src
/
specialhost
/
flextr.c
< prev
next >
Wrap
Text File
|
1991-01-29
|
4KB
|
112 lines
/****************************************************************/
/* The function "extract_one()" of this module if from the */
/* file flextr.c of the FBM Library 0.9. */
/* */
/* Some changes are made, to work with one bit per pixel */
/* instead of 1 byte. */
/* */
/* The warning "out of bounds" is deleted, because I didn't */
/* understand it. */
/* */
/* 27-07-90 Georg Hessmann (hes) */
/* 14-11-90 Michael Illgner, speed improvement */
/****************************************************************/
/*****************************************************************
* flextr.c: FBM Library 0.9 (Beta test) 07-Mar-89 Michael Mauldin
*
* Copyright (C) 1989 by Michael Mauldin. Permission is granted to
* use this file in whole or in part provided that you do not sell it
* for profit and that this copyright notice is retained unchanged.
*
* flextr.c: Extract a rectangle and/or resize it.
*
* CONTENTS
* extract_fbm (input, output, xo, yo, w, h, ow, oh, title, credits)
*
* EDITLOG
* LastEditDate = Tue Mar 7 19:56:56 1989 - Michael Mauldin
* LastFileName = /usr2/mlm/src/misc/fbm/flextr.c
*
* HISTORY
* 07-Mar-89 Michael Mauldin (mlm) at Carnegie Mellon University
* Beta release (version 0.9) mlm@cs.cmu.edu
*
* 12-Nov-88 Michael Mauldin (mlm) at Carnegie-Mellon University
* Created.
*****************************************************************/
void extract_one(UBYTE *BMin, UBYTE *BMout,
USHORT inlen, USHORT outlen, /* line length in bytes */
USHORT w, USHORT h, /* size input plane in pixel */
USHORT ow, USHORT oh) /* size output plane in pixel */
{
USHORT xf, yf, xi, yi, byte, row, col;
USHORT InByte1, InByte2, InBit1, InBit2, OutByte, OutBit;
UBYTE *InRow1, *InRow2, *OutRow, BitMask;
ULONG dc;
const UBYTE Bit[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
const ULONG wh2 = ((ULONG)ow * (ULONG)oh) / 2;
const USHORT xm = w % ow;
const USHORT xd = w / ow;
const USHORT ym = h % oh;
const USHORT yd = h / oh;
const ULONG InSkip = yd * inlen;
if (w == ow && h == oh)
{
InRow1 = BMin; OutRow = BMout;
for(row=0; row<h; row++) for(byte=0; byte<inlen; byte++) *OutRow++ = *InRow1++;
}
else
{
yf = 0; yi = 0;
OutRow = BMout; InRow1 = BMin; InRow2 = BMin + inlen;
for(row=0; row<oh; row++)
{
if (!(row % 100)) pline(" work on line %d (from %d lines)", row, oh);
xf = 0; xi = 0;
for(col=0; col<ow; col++)
{
OutByte = col >> 3; OutBit = col & 0x07;
InByte1 = xi >> 3; InBit1 = xi & 0x07;
InByte2 = (xi+1) >> 3; InBit2 = (xi+1) & 0x07;
BitMask = Bit[OutBit];
if (xi > w-2 || yi > h-2)
{
if ((xi == w-1 && yi <= h-1) || (yi == h-1 && xi <= w-1))
{
if (InRow1[InByte1] & Bit[InBit1]) OutRow[OutByte] |= BitMask;
}
else OutRow[OutByte] |= BitMask;
}
else
{
dc = 0;
if (InRow1[InByte1] & Bit[InBit1]) dc += (ow-xf)*(oh-yf);
if (InRow2[InByte1] & Bit[InBit1]) dc += (ow-xf)*yf;
if (InRow1[InByte2] & Bit[InBit2]) dc += xf*(oh-yf);
if (InRow2[InByte2] & Bit[InBit2]) dc += xf*yf;
if (dc > wh2) OutRow[OutByte] |= BitMask;
}
xf += xm; xi += xd;
if (xf >= ow)
{
xf -= ow;
xi ++;
}
}
OutRow += outlen;
yf += ym; InRow1 += InSkip; yi += yd;
if (yf >= oh)
{
yf -= oh;
InRow1 += inlen; yi++;
}
InRow2 = InRow1 + inlen;
}
}
}